package com.zhongan.ui.demo;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;

@RefreshScope
@Service
public class HelloService {

	@Value("${name:default name}")
	private String name;

	@Autowired
	private RestTemplate restTemplate;

	private final String SERVICE_NAME = "erueka-client-01";

	@HystrixCommand(fallbackMethod = "hello22222222222222222")
	public String hello() {
		String response = restTemplate.getForObject("http://" + SERVICE_NAME + "/hello", String.class); 
		return response + "," + name;
	}

	public String hello22222222222222222() {
		System.out.println("熔断机制执行");
		return "hello hystrix!" + name;
	}

}
